$(function(){
	showCondition(true, 0, 0, 1,[]);//加载查询条件
	// 定义加载对象。 divId、指标code、 指标名称、  数据data
	var groupCnt = {"id":"groupCnt","quotas":[
	                               {"code":"DRGCount","title":"DRGs组数"},
	                               {"code":"PayGroupDrgCnt","title":"付费病组数","link":"openDrgList"},
	                               {"code":"PayGroupDrgCnt|DRGCount","title":"付费病组数占比(%)"},
	                               {"code":"PayGroupOverFeeDrgCnt","title":"付费超标病组组数","link":"openDrgList"},
	                               {"code":"PayGroupOverFeeDrgCnt|PayGroupDrgCnt","title":"付费病组中超标病组占比(%)"},
	                               {"code":"PayGroupOverFeeDrgCnt|DRGCount","title":"病组中付费超标病组占比(%)"} 
	                               ],
	                               "data":null} ;
	var inGroupCnt = {"id":"inGroupCnt","quotas":[{"code":"InCaseCnt","title":"入组病例数"},
                                  {"code":"PayGroupCnt","title":"付费病组病例数"},
                                  {"code":"PayGroupCnt|InCaseCnt","title":"付费病组病例数占比(%)"},
                                  {"code":"PayGroupOverFeeCnt","title":"付费病组超标病例数"},
                                  {"code":"PayGroupOverFeeCnt|PayGroupCnt","title":"付费病组病例中超标病例占比(%)"},
                                  {"code":"PayGroupOverFeeCnt|InCaseCnt","title":"入组病例中付费超标病例占比(%)"}
                                  ],
	                              "data":{}} ;
	var groupDis = {"id":"groupDis", "quotas": [{"code":"NoPayGroupOverFeeDrgCnt","title":"非付费病组超标组数"}],"data":{"inner":[{"name":"付费病组"} ,{"name":"非付费病组"}],
		             "outer":[{"name":"付费超标病组"} ,{"name":"付费未超标病组"} ,{"name":"非付费超标病组"} ,{"name":"非付费未超标病组"}]
		            } 
		                                 } ;
	var inGroupDis = {"id":"inGroupDis", "quotas": [{"code":"NoPayGroupOverFeeCnt","title":"非付费病组超标病例数"}],"data":{"inner":[{"name":"付费病组病例"} , {"name":"非付费病组病例"}],
	                 "outer":[ {"name":"超标病例(付费)"} ,{"name":"付费未超标病例(付费)"} ,{"name":"超标病例(非付费)"} ,{"name":"非付费未超标病例(非付费)"}]} 
										} ;
	var profitLossQuotas = [{"code":"PayGroupExpectIncome","title":"预计收入(万元)"},  {"code":"PayGroupActualFee","title":"实际支出(万元)"} ] ;
	var payGroupMdcAll = {"id":"payGroupMdcAll","idToal":"profitLossHospMdc","monitorType":"mdc","quotas":profitLossQuotas, "data":{}} ;
	var payGroupDepAll = {"id":"payGroupDepAll","idToal":"profitLossHospDep","monitorType":"dep","quotas":profitLossQuotas, "data":{}} ;
	
	var payGroupDrgInMdc = {"id":"payGroupDrgInMdc","idToal":"profitLossTotalDrg","monitorType":"drgs","quotas":profitLossQuotas,  "data":{}} ;
	var payGroupDrgInDep = {"id":"payGroupDrgInDep","idToal":"profitLossTotalDep","monitorType":"drgs","quotas":profitLossQuotas, "data":{}} ;
	
	var indexQuadrantDisDrgInMdc = {"id":"indexQuadrantDisDrgInMdc","quotas":[{"code":"PayGroupDrugMaterFeeEff"},{"code":"PayGroupFeeEff"},{"code":"PayGroupCnt"}],"data":{}} ;
	var indexQuadrantDisDrgInDep = {"id":"indexQuadrantDisDrgInDep","quotas":[{"code":"PayGroupDrugMaterFeeEff"},{"code":"PayGroupFeeEff"},{"code":"PayGroupCnt"}],"data":{}} ;
	// 加载付费病组组数  和 付费病组分布图
	loadDataPayGroup(groupCnt,loadCntDiv,null,groupDis) ;
	// 付费病组入组病例数 和 付费病组入组病例分布图
	loadDataPayGroup(inGroupCnt,loadCntDiv,null,inGroupDis) ;
	// 加载盈亏统计
	// 全部付费病组 - 合计
	loadDataPayGroup(payGroupMdcAll,drawProfitLossHosp,{"monitorType":"hosp"}) ;
	// 全部付费病组 - 和 第一个mdc下的 付费病组
	loadDataPayGroup(payGroupMdcAll,drawProfitLossMdc,{"monitorType":payGroupMdcAll.monitorType} ,payGroupDrgInMdc) ;
    // 绘制象限分布图
	loadDataPayGroup(indexQuadrantDisDrgInMdc,processIndexQuadrantDisData,{"monitorType":"drgs","isPayGroup":"1"}) ;
	
	// 结余统计页签事件
	$("#" +tabId+" #profitLossTab").on("click","li",function() {
		var href = $(this).children("a").attr("href") ;
		if(href == "#payGroupDrg") {
			loadDataPayGroup(payGroupMdcAll,drawProfitLossHosp,{"monitorType":"hosp"}) ;
			loadDataPayGroup(payGroupMdcAll,drawProfitLossMdc,{"monitorType":payGroupMdcAll.monitorType} ,payGroupDrgInMdc) ;
		} else if(href == "#payGroupDep") { // 各 科室 统计
			loadDataPayGroup(payGroupDepAll,drawProfitLossHosp,{"monitorType":"hosp"}) ;
			loadDataPayGroup(payGroupDepAll,drawProfitLossDep,{"monitorType":payGroupDepAll.monitorType,"isPayGroup":"1"} ,payGroupDrgInDep) ;
		}
	}) ;
	
	$("#" +tabId+" .table").on("click","a",function() {
		var drgCode = $(this).attr("drgCode") ;
		var param = jQuery.extend(true, {}, paramTabPage[tabId]);
		param.pType = "1" ;
		param.pardrgCode = drgCode ;
		param.desc = $(this).html() ;
		openTab('/pages/paygroup/paygroupAnalysis_drg.jsp', drgCode + "病组费用分析", "paygroupAnalysis_drg" , "paygroupAnalysis_drg", param);
	}) ;
})

/**
 * 处理指标象限分布图数据
 * @@param thisObj
 * @void
 * @ Discription:
 * @paygroupAnalysis.js
 */
function processIndexQuadrantDisData(thisObj) {
	var xyAx = {"xAxis":{"desc":"药耗费用消耗指数"},"yAxis":{"desc":"费用消耗指数"}};
	var data = [{"data":[]}] ;
	var drgData = thisObj.data.drgs ;
	for (var o in drgData) {
		if(!isNaN(drgData[o].PayGroupDrugMaterFeeEff) && !isNaN(drgData[o].PayGroupFeeEff) ) {
			var x = drgData[o].PayGroupDrugMaterFeeEff;
			var y = drgData[o].PayGroupFeeEff;
			var color = "" ;
			var quadrant = "" ;
			if(x>1 && y>1){
				quadrant = 1;
				color = '#f05a72';
			} else if(x>1 && y<1){
				quadrant = 4;
				color = '#fed503';
			} else if(x<1 && y>1){
				quadrant = 2;
				color = '#5bc0de';
			} else if(x<1 && y<1) {
				quadrant = 3;
				color = '#66cc66';
			} else {
				quadrant = 5;
			}
			var dt = {"x":x,"y":y,"symbolValue":drgData[o].PayGroupCnt,"color":color,"quadrant":quadrant,"ccode":drgData[o].ccode,"desc":drgData[o].ddesc}
			data[0].data.push(dt) ;
			thisObj.data.drgs[o].quadrant = quadrant;
		} else {
			thisObj.data.drgs[o].quadrant = 5 ;
		}
	}
	var chartParams = {} ;
	// 根据所在象限放在相应表格里
	if(thisObj.id == "indexQuadrantDisDrgInMdc") {
		indexQuadrantDisTable(thisObj,".quadrantDisDrg .quadrantDis") ;
	} 
	
	if(data[0].data.length > 0) {
		var xmin = data[0].data.sort(order("x"))[0].x;
		var xmax = data[0].data.sort(order("x"))[data[0].data.length-1].x;
		var ymin = data[0].data.sort(order("y"))[0].y;
		var ymax = data[0].data.sort(order("y"))[data[0].data.length-1].y;
		// 延长边界范围
		xmin = Math.floor(xmin-0.2*Math.abs(xmin));
		xmax = Math.ceil(xmax+0.2*Math.abs(xmax));
		ymin = Math.floor(ymin-0.2*Math.abs(ymin));
		ymax = Math.ceil(ymax+0.2*Math.abs(ymax));
		var config = {"xmin":xmin,"xmax":xmax, "ymin":ymin,"ymax":ymax,
				"symbolValueMin":data[0].data.sort(order("symbolValue"))[0].symbolValue,"symbolValueMax":data[0].data.sort(order("symbolValue"))[data[0].data.length-1].symbolValue}
		chartParams = config ;
	}
	var symboSizeFunc=function(data){
		var region = chartParams.symbolValueMax-chartParams.symbolValueMin;
		if(region == 0)
		{
			region = 1;
		}
		//归一化处理
		return (((data[2]-chartParams.symbolValueMin)/region)*5+1)*10;
	}
	chartParams.symboSizeFunc=symboSizeFunc;
	chartParams.isDataZoom=true;
	//散点图提示框处理函数
	chartParams.formatterFunc=function (params) {
    	//修改散点图悬浮框显示样式(黑框)
		if(params.data.value[0]==undefined||params.data.value[1]==undefined){
			return ;
		} else {
			var str="";
	    	str+=(params.data.code+"-"+params.name)+ "<br/>" +"("+params.data.value[0]+","+params.data.value[1]+")";    
	    	if(chartParams.symbolValueMin&&chartParams.symbolValueMin){//如果添加总权重 用于求散点图点的大小，则在散点图中添加总权重的提示信息
	    		str+="<br/>病例数:" +params.data.value[2];
		    }
	    	return str;
		}
    	
	};
	//散点图点击事件
	chartParams.callBack_click=function(value){
		if(value.componentType != "markLine")
		{//标记线不添加点击事件
			var drgCode = value.data.code;
			var drgDesc = value.data.name;
			var param = jQuery.extend(true, {}, paramTabPage[tabId]);
			param.pType = "1" ;
			param.pardrgCode = drgCode ;
			param.desc = drgCode+"-"+drgDesc;
			openTab('/pages/paygroup/paygroupAnalysis_drg.jsp', drgCode + "病组费用分析", "paygroupAnalysis_drg" , "paygroupAnalysis_drg", param);
		}	
	}
	scatterChartsWithLine($("#"+tabId+" #" + thisObj.id),data,xyAx,"病组费用消耗指数和药耗费用消耗指数象限分布图",{lineStyle: {color:'#abc',normal: {type: 'solid'}},data:[{name:"药耗费用消耗指数基准线",xAxis: 1},{name:"时间消耗指数基准线",yAxis: 1}]},chartParams);
}

/**
 *  绘制象限表格
 * @@param thisObj 
 * @@param clas  表格样式
 * @void
 * @ Discription:
 * @paygroupAnalysis.js
 */
function indexQuadrantDisTable(thisObj,clas) {
	var drgsData = thisObj.data.drgs  ;
//	 将不同象限的病组放入相应的数组
	var td = [[],[],[],[],[]] ;
	for(var o in drgsData) {
//		if(drgsData[o].quadrant != 5 ) {
//			td[drgsData[o].quadrant-1].push("<a drgCode=\""+drgsData[o].ccode+"\">"+drgsData[o].ccode+"-"+drgsData[o].ddesc+"</a>") ;
//		} else {
//			td[drgsData[o].quadrant-1].push( drgsData[o].ccode+"-"+drgsData[o].ddesc ) ;
//		}
		td[drgsData[o].quadrant-1].push("<a drgCode=\""+drgsData[o].ccode+"\">"+drgsData[o].ccode+"-"+drgsData[o].ddesc+"</a>") ;

	}

	// 将数组的存的对象放入相应的单元格
	$.each(td,function(i,n){
		td[i].join(",")
		$("#"+tabId+" "+clas).eq(i).empty();
		$("#"+tabId+" "+clas).eq(i).append(td[i].join("&nbsp;,&nbsp;"));
		$("#"+tabId+" "+clas).eq(i).prev().empty() ;
		$("#"+tabId+" "+clas).eq(i).prev().html(td[i].length) ;
	}) ;
}



/**
 * 
 * @@param thisObj 加载对象
 * @void
 * @ Discription: 全部付费病组  总体数据
 * @paygroupAnalysis.js 
 */
function drawProfitLossHosp(thisObj) {
	var data = null ;
	if(thisObj.data.hosp) {
		data = thisObj.data.hosp[0] ;
	} else if(thisObj.data.mdc) {
		data = thisObj.data.mdc[0] ;
	} else if(thisObj.data.dep) {
		data = thisObj.data.dep[0] ;
	}
	if(data != null) {
		$("#"+tabId+" #"+thisObj.idToal +" .font2").each(function(i){
			if( i == 0) {
				$(this).text(formatNumPayGroup(data.PayGroupActualFee,2)) ; // PayGroupExpectIncome
			} else if( i == 1) {
				$(this).text(formatNumPayGroup(data.PayGroupExpectIncome,2)) ;
			} else if( i == 2) {
				if(isNaN(data.PayGroupExpectIncome)) {
					$(this).text("-") ;
				} else {
					$(this).text((formatNumPayGroup((data.PayGroupExpectIncome-data.PayGroupActualFee),2)));
				}
			}
		})
	}
}

/**
 * 
 * @@param thisObj 本次处理的对象
 * @@param relatedObj 依赖本次数据的另一个加载对象
 * @void
 * @ Discription: 
 * @paygroupAnalysis.js
 */
function drawProfitLossMdc(thisObj,relatedObj) {
	var indexQuadrantDisDrgInMdc = {"id":"indexQuadrantDisDrgInMdc","quotas":[{"code":"PayGroupDrugMaterFeeEff"},{"code":"PayGroupFeeEff"},{"code":"PayGroupCnt"}],"data":{}} ;
	// 查询第一个的汇总信息
	relatedObj.data.mdc = [] ;  
	relatedObj.data.mdc.push(thisObj.data.mdc[0]);
	drawProfitLossHosp(relatedObj) ;
	if(!thisObj.data.mdc.length) {
		thisObj.data.mdc.push({"ccode":" - "}) ;
	}
	$('#'+tabId+' #selectedMdc').html(thisObj.data.mdc[0].ccode+"下付费病组");
	$('#'+tabId+' #selectedMdc').attr("code",thisObj.data.mdc[0].ccode);
	// 绘制右侧mdc 下的 drg
	var param2 = {"monitorType":relatedObj.monitorType,"mdcCode":thisObj.data.mdc[0].ccode} ;
	loadDataPayGroup(relatedObj,drawProfitLossDrg,param2) ;
	var labelRight = {
		    normal: {
		        position: 'right'
		    }
	};
	var mdcData = thisObj.data.mdc ;
	var data = [] ;
	var title = [] ;
	for (var o in mdcData) {
		var value = (mdcData[o].PayGroupExpectIncome - mdcData[o].PayGroupActualFee).toFixed(2) ;
		data.push({value:value, label: labelRight}) ;
		title.push(mdcData[o].ccode) ;
	}
    var paramEch = {"title":"各MDC专业下付费病组结余情况","series":[{"name":"结余","data":data}],"y":{"data":title}};
    if(data.length>5) {
        paramEch.dataZoom = [{type: 'inside',yAxisIndex: 0,filterMode: 'empty',start: 0,end: 500/data.length}];
    }
    var myChart = drawPayGroupBarChart(thisObj.id,paramEch,null) ;
    myChart.getZr().on('click',function (params) {
        var pointInPixel= [params.offsetX, params.offsetY];
        if (myChart.containPixel('grid',pointInPixel)) {
            var pointInGrid=myChart.convertFromPixel({seriesIndex:0},pointInPixel);
            var yIndex=pointInGrid[1];
            //获取当前图表的option
            var op=myChart.getOption();
            //获得图表中我们想要的数据
            var mdcCode=op.yAxis[0].data[Math.abs(yIndex)];
            $('#'+tabId+' #selectedMdc').html(mdcCode+"下付费病组");
            $('#'+tabId+' #selectedMdc').attr("code",mdcCode);
            // 更新右侧 付费病组 drg
            relatedObj.data.mdcCode = payGroupFilter(thisObj.data.mdc, "ccode",mdcCode) ;
            // 绘制 某个mdc 下的汇总数据
            drawProfitLossHosp(relatedObj,mdcCode) ;
            // 绘制某个mdc下的付费病组 结余情况
            var param = {"mdcCode":mdcCode,"monitorType":"drgs"} ;
            loadDataPayGroup(relatedObj,drawProfitLossDrg,param,null) ;
        }
    });
}
/**
 * 
 * @@param thisObj
 * @@param relatedObj 右侧的付费病组对象
 * @void
 * @ Discription: 绘制科室角度结余图
 * @paygroupAnalysis.js
 */
function drawProfitLossDep(thisObj,relatedObj) {
	var indexQuadrantDisDrgInDep = {"id":"indexQuadrantDisDrgInDep","quotas":[{"code":"PayGroupDrugMaterFeeEff"},{"code":"PayGroupFeeEff"},{"code":"PayGroupCnt"}],"data":{}} ;
	// 查询第一个的汇总信息
	relatedObj.data.dep = [] ;  
	relatedObj.data.dep.push(thisObj.data.dep[0]);
	drawProfitLossHosp(relatedObj) ;
	$('#'+tabId+' #selectedDep').html(thisObj.data.dep[0].ddesc+"下付费病组");
	$('#'+tabId+' #selectedDep').attr("code",thisObj.data.dep[0].ccode);
	// 绘制右侧dep 下的 drg
	var param2 = {"monitorType":relatedObj.monitorType,"depCode":thisObj.data.dep[0].ccode} ;
	loadDataPayGroup(relatedObj,drawProfitLossDrg,param2) ;
//	loadDataPayGroup(indexQuadrantDisDrgInDep,processIndexQuadrantDisData,{"depCode":thisObj.data.dep[0].ccode,"monitorType":"drgs"}) ;

	
	var labelRight = {
		normal: {
			position: 'right'
		}
	};
	var depData = thisObj.data.dep ;
	var data = [] ;
	var title = [] ;
	for (var o in depData) {
		var value = (depData[o].PayGroupExpectIncome - depData[o].PayGroupActualFee).toFixed(2) ;
		data.push({value:value, label: labelRight}) ;
		title.push(depData[o].ddesc) ;
	}
	var callback = function (params) {
		$('#'+tabId+' #selectedDep').html(params.name+"下付费病组");
		// 更新右侧 付费病组 drg
		relatedObj.data.dep = payGroupFilter(thisObj.data.dep, "ddesc",params.name) ;
		$('#'+tabId+' #selectedDep').attr("code",relatedObj.data.dep[0].ccode);
		// 绘制 某个dep 下的汇总数据
		drawProfitLossHosp(relatedObj) ;
		// 绘制某个dep下的付费病组 结余情况
		var param = {"depCode":relatedObj.data.dep[0].ccode,"monitorType":"drgs"} ;
		loadDataPayGroup(relatedObj,drawProfitLossDrg,param,null) ;
		// 绘制指标象限分布图
//		loadDataPayGroup(indexQuadrantDisDrgInDep,processIndexQuadrantDisData,{"depCode":relatedObj.data.dep[0].ccode,"monitorType":"drgs"}) ;

	}
	var paramEch = {"title":"各科室下付费病组结余情况", "series":[{"name":"结余","data":data}],"y":{"data":title}};
	if(data.length>5)
	{
		paramEch.dataZoom = [{type: 'inside',yAxisIndex: 0,filterMode: 'empty',start: 0,end: 500/data.length}];
	}
	drawPayGroupBarChart(thisObj.id,paramEch,callback) ;
}

/**
 *  处理 mdc 下病组数据
 * @@param payGroupDrgInMdc 处理的数据对象
 * @void
 * @ Discription:
 * @paygroupAnalysis.js
 */
function drawProfitLossDrg(payGroupDrgInMdc) {
	var legend = {
        data:['预计结余', '实际支出', '预计收入']
    } ;
	
	var paramEch = {"title":"付费病组预计结余图","legend":legend,
			"series":[{"name":"预计结余","data":[] },
		          	  {"name":"预计收入","data":[] },
			          {"name":"实际支出","data":[] }
			          ],"y":{"data":[]}};
	var drgsData = payGroupDrgInMdc.data.drgs ;
	for(var o in drgsData) {
		paramEch.series[0].data.push(formatNumPayGroup(drgsData[o].PayGroupExpectIncome-drgsData[o].PayGroupActualFee,2)) ;
		paramEch.series[1].data.push(formatNumPayGroup(drgsData[o].PayGroupExpectIncome,2)) ;
		paramEch.series[2].data.push(-formatNumPayGroup(drgsData[o].PayGroupActualFee,2)) ;
		paramEch.y.data.push(drgsData[o].ccode) ;
	} ;
    paramEch.formatter = function (value) {
        var tips = '';
        if(value!=undefined && value.length>0){
            for(var i = 0; i <value.length; i++) {
                var val = value[i].value;
                if (value[i].seriesName.indexOf("支出")>-1) {
                    val = Math.abs(value[i].value) ;
                }
                if(val == 'undefined') {
                    val = '';
                }
                if(i==0) {
                    tips = value[i].seriesName+':'+val;
                } else {
                    tips += '</br>' +value[i].seriesName+':'+val;
                }
            }
        }
        return tips;
    }
    var myChart = drawPayGroupBarChart(payGroupDrgInMdc.id,paramEch) ;
    myChart.getZr().on('click',function (params) {
        var pointInPixel= [params.offsetX, params.offsetY];
        if (myChart.containPixel('grid',pointInPixel)) {
            var pointInGrid=myChart.convertFromPixel({seriesIndex:0},pointInPixel);
            var yIndex=pointInGrid[1];
            //获取当前图表的option
            var op=myChart.getOption();
            //获得图表中我们想要的数据
            var drgCode=op.yAxis[0].data[Math.abs(yIndex)];
            $("#"+tabId+" #indexQuadrantDisDrgInMdcTable a[drgcode='"+drgCode+"']").click() ;
        }
    });
}





/**
 * 
 * @@param thisObj
 * @@param relatedObj
 * @void
 * @ Discription:绘制 付费病组监测
 * @paygroupAnalysis.js
 */
function loadCntDiv(thisObj,relatedObj) {
	var container = $("#" +tabId+" #"+thisObj.id+"") ;
	var str = "" ;
	for(var o in thisObj.quotas) {
		str+="<div class=\"col-md-2 column\">"  ;
		// 计算指标
		if(thisObj.quotas[o].code.indexOf("|") > 0) {
			var quota = thisObj.quotas[o].code.split("|") ;
			var value = "" ;
			if(thisObj.data[0]) {
				value = formatNumPayGroup((thisObj.data[0][quota[0]]/thisObj.data[0][quota[1]]*100),2) ;
			}
			str+="<div class=\"font2\">"+value+"</div>"  ;
			if(thisObj.data[0]) {
				str+="<div class=\"font1\">"+formatNumPayGroup(thisObj.data[0][quota[0]],0)+"/"+formatNumPayGroup(thisObj.data[0][quota[1]],0)+"</div>";
			} else {
				str+="<div class=\"font1\"></div>";
			}
		} else { 
			// 加链接的指标
			if(thisObj.quotas[o].link && thisObj.data[0]) {
				str+="<div class=\"font2\"><a href=\"javascript:"+thisObj.quotas[o].link+"('"+thisObj.quotas[o].code+"')\">"+ formatNumPayGroup(thisObj.data[0][thisObj.quotas[o].code],0) +"</a></div>"  ;
			} else if(thisObj.data[0]) {
				str+="<div class=\"font2\">"+ formatNumPayGroup(thisObj.data[0][thisObj.quotas[o].code],0) +"</div>"  ;
			}
			str+= "<div class=\"font1\"><br//></div>";
		}
		str+="<div class=\"font1\">"+thisObj.quotas[o].title+"</div>" ;
		str+= "</div>" ;
	}
	container.html(str) ;
	drawGroupDisEchart(relatedObj,thisObj) ;
}

/**
 * 嵌套环形图
 * @@param thisObj 本次加载对象
 * @@param relatedObj 关联加载对象
 * @void
 * @ Discription: 付费病组分布图
 * @paygroupAnalysis.js
 */
function drawGroupDisEchart(thisObj,relatedObj) {
	var data = relatedObj.data[0] ;
	var option = {
			title: {
		        text: '全院付费病组数及其超标病组数占比图',
		        padding: 5,
		        textStyle : {
		        	fontStyle:'normal' ,
		        	fontWeight:'normal' ,
		        	fontFamily:'microsoft yahei' ,
		        	fontSize:'14' 
		        }
		    },
		    tooltip: {
		        trigger: 'item',
		        formatter: "{a} <br/>{b}: {c} ({d}%)"
		    },
		    toolbox: {
		        show : true,
		        feature : {
		            saveAsImage : {show: true}
		        }
		    },
		    legend: {
		        orient: 'vertical',
		        x: 'left',
		        data:[]
		    },
		    series: [
		        {
		            name:'付费病组占比',
		            type:'pie',
		            selectedMode: 'single',
		            radius: [0, '30%'],
		            label: {
		                normal: {
		                	color: "black" ,
		                    position: 'inner'
		                }
		            },
		            labelLine: {
		                normal: {
		                    show: false
		                }
		            },
		            data:[{ value:0, name:'付费病组', selected:false },
		                  {value:0, name:'非付费病组' } 
		            ]
		        },
		        {
		            name:'付费病组占比',
		            type:'pie',
		            radius: ['40%', '55%'],
		            data:[
		                {value:0, name:'' },
		                {value:0, name:'' },
		                {value:0, name:'' },
		                {value:0, name:'' } 
		            ]
		        }
		    ]
		};
	if( thisObj.id == "groupDis" && data) {
		// 付费病组
		option.series[0].data[0].value = data.PayGroupDrgCnt ;
		// 非付费病组
		option.series[0].data[1].value = data.DRGCount - data.PayGroupDrgCnt ;
		// 付费超标病组
		option.series[1].data[0].value = data.PayGroupOverFeeDrgCnt ;
		// 付费未超标病组
		option.series[1].data[1].value = data.PayGroupDrgCnt - data.PayGroupOverFeeDrgCnt ;
		// 非付费超标病组
		option.series[1].data[2].value = data.NoPayGroupOverFeeDrgCnt ;
		// 非付费未超标病组
		option.series[1].data[3].value = data.DRGCount - data.PayGroupDrgCnt - data.NoPayGroupOverFeeDrgCnt ;
	} else if( thisObj.id == "inGroupDis" && data) {
		// 付费病例
		option.series[0].data[0].value = data.PayGroupCnt ;
		// 非付费病例
		option.series[0].data[1].value = data.InCaseCnt - data.PayGroupCnt ;
		// 付费超标病例
		option.series[1].data[0].value = data.PayGroupOverFeeCnt ;
		// 付费未超标病例
		option.series[1].data[1].value = data.PayGroupCnt - data.PayGroupOverFeeCnt ;
		// 非付费超标病例
		option.series[1].data[2].value = data.NoPayGroupOverFeeCnt ;
		// 非付费未超标病例
		option.series[1].data[3].value = data.InCaseCnt - data.PayGroupCnt - data.PayGroupOverFeeCnt ;
	}
	option.series[0].data[0].name =  thisObj.data.inner[0].name ;
	option.series[0].data[1].name = thisObj.data.inner[1].name ;
	option.series[1].data[0].name = thisObj.data.outer[0].name ;
	option.series[1].data[1].name =thisObj.data.outer[1].name ;
	option.series[1].data[2].name = thisObj.data.outer[2].name ;
	option.series[1].data[3].name = thisObj.data.outer[3].name ;
//	var myChart = echarts.init(document.getElementById(thisObj.id),'infographic');
	var myChart=initSeting($("#"+tabId+" #"+thisObj.id),option,{});
	myChart.setOption(option);
}

/**
 * 
 * @chenhanin
 * @void
 * @ Discription:付费病组管理
 * @paygroupAnalysis.js
 */
function paygroupManage(){
	$.post(contextPath + "/pages/common/top-dialog.jsp").done(function(data) {
		var dialog  = $(data);
		dialog.find(".modal-dialog").attr("id","payGroupListDialog");
        dialog.find(".modal-body").css("min-height", "440px");
        dialog.find(".modal-body").css("width", "60%");
		dialog.find(".modal-title").html("付费病组管理");
		dialog.modal({
			keyboard: false,
			backdrop:"static"
		}).on({
			"hidden.bs.modal" : function(){
				$(this).remove();
				searchByCondition();
			},
			"shown.bs.modal" : function(){
				payGroupList();
			}
		});
 });
}
/**
 * 
 * @ Discription:付费病组列表
 * @Autor ：mazhaoyan
 * void
 * paygroupAnalysis.js
 * 2017年8月29日下午4:12:48
 */
function payGroupList(){
	var payGroupListDialog=$("#payGroupListDialog");
	payGroupListDialog.find("#echartcq4").empty();
	payGroupListDialog.find("#echartcq4").html("<table id=\"paygroupManageTable\" class=\"table\"></table>");
	// 初始化 DRG付费病组列表 表格
	var payGroupCnt = transformFloat($("#"+tabId+" #inGroupCnt > div:nth-child(1) > div:first").text())
	var columns=[
                  	{"data": "","sClass": "details-control","width":"20px"},
                  	{"data": "ddesc","title":"MDC代码及描述",
                  		"render": function(obj, type, full) {
                  			return full.ccode + "-" +full.ddesc ;
	                     }
              		},
                  	{"data": "PayGroupDrgCnt","title":"付费病组数" },
                  	{"data": "PayGroupCnt","title":"病例数" ,
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.PayGroupCnt,0) ;
	           			}
                  	},
                  	{"data": "PayGroupCntR","title":"付费病组病例数占比(%)",
          				"render": function(obj, type, full) {
          					return formatNumPayGroup(full.PayGroupCnt/payGroupCnt*100,2) ;
	                     }
                  	},
                  	{"data": "PayGroupOverFeeDrgCnt","title":"超标病组数" ,
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.PayGroupOverFeeDrgCnt,0) ;
	           			}
                    },
              		{"data": "PayGroupOverFeeDrgCntR","title":"超标病组数占比(%)",
              			"render": function(obj, type, full) {
              				if(full.PayGroupOverFeeDrgCnt && full.PayGroupDrgCnt) {
              					return  formatNumPayGroup(full.PayGroupOverFeeDrgCnt/full.PayGroupDrgCnt*100,2) ;
              				} else {
              					return  formatNumPayGroup("0",2) ;
              				}
              			}
              		}
                 ];
	var paramsDataTables={lengthChange:false,ordering:false,stateSave:true,info:false, scrollY:"300px" ,tableTitle:"DRG付费病组列表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
	paramsDataTables.buttons=[{"text": "添加","action": function ( e, dt, node, config) {
			addPayGroup() ;
		}
	}];
	var paygroupManageTable = {"id":"paygroupManageTable","quotas":[
	       	                          {"code":"PayGroupDrgCnt","title":"付费病组数"},
	       	                          {"code":"InCaseCnt","title":"入组病例数",
			       	   	           			"render": function(obj, type, full) {
			       		           				return formatNumPayGroup(full.InCaseCnt,0) ;
			       		           			}
	       	                          },
	       	                          {"code":"PayGroupCnt","title":"付费病组病例数",
			       	   	           			"render": function(obj, type, full) {
			       		           				return formatNumPayGroup(full.PayGroupCnt,0) ;
			       		           			}
	       	                          },
	       	                          {"code":"PayGroupCnt|InCaseCnt","title":"付费病组病例数占比(%)",
			       	   	           			"render": function(obj, type, full) {
			       		           				return formatNumPayGroup(full.PayGroupCnt/full.InCaseCnt,2) ;
			       		           			}
	       	                          },
	       	                          {"code":"PayGroupOverFeeDrgCnt","title":"付费超标病组组数",
			       	   	           			"render": function(obj, type, full) {
			       		           				return formatNumPayGroup(full.PayGroupOverFeeDrgCnt,2) ;
			       		           			}
	       	                          },
	       	                          {"code":"PayGroupOverFeeDrgCnt|PayGroupDrgCnt","title":"付费病组中超标病组占比(%)"}
	       	                        ],
	       	                     "data":{} } ;
	
	
	var param = {"monitorType":"mdc"} ;
	// 查询病组和相应的指标
	// $.when(loadDataPayGroup(paygroupManageTable,null,param),findAllDRGPayGroup("1")).done(function (data1,data2) {
     //    var oaTable = payGroupListDialog.find("#echartcq4 #paygroupManageTable").dataTableBasic(columns,paygroupManageTable.data.mdc,paramsDataTables) ;
     //    function format( d ) {
     //        return '<div class="col-xs-12" style="background:rgba(255,255,255,0.5);">'
     //            +'	<div class="row">'
     //            +'		<div class="col-xs-12" id= "'+d+'"></div>'
     //            +'   </div>'
     //            +'</div>';
     //    }
     //    payGroupListDialog.find("#paygroupManageTable").on("click", "td.details-control", function (){
     //        var nTr = $(this).closest("tr");
     //        var row = oaTable.row( nTr );
     //        var aData = row.data();
     //        if (row.child.isShown()) { //判断是否已打开
     //            row.child.hide();
     //            nTr.removeClass("shown");
     //        } else {
     //            nTr.addClass("shown");
     //            var mdcCode = aData.ccode ;
     //            row.child(format(mdcCode)).show();
     //            // 查询MDC下的DRG
     //            findDrgByMdc(payGroupCnt,mdcCode,payGroupListDialog);
     //        }
     //    });
    // })

	loadDataPayGroup(paygroupManageTable,function(thisObj) {
		var oaTable = payGroupListDialog.find("#echartcq4 #paygroupManageTable").dataTableBasic(columns,thisObj.data.mdc,paramsDataTables) ;
		function format( d ) {
		    return '<div class="col-xs-12" style="background:rgba(255,255,255,0.5);">'
				    +'	<div class="row">'
			        +'		<div class="col-xs-12" id= "'+d+'"></div>'
			        +'   </div>'
			        +'</div>';
		}
		payGroupListDialog.find("#paygroupManageTable").on("click", "td.details-control", function (){
			var nTr = $(this).closest("tr");
			var row = oaTable.row( nTr );
	        var aData = row.data();
	        if (row.child.isShown()) { //判断是否已打开
				row.child.hide();
				nTr.removeClass("shown");
			} else {
				nTr.addClass("shown");
	        	var mdcCode = aData.ccode ;
	        	row.child(format(mdcCode)).show();
	        	// 查询MDC下的DRG
	            findDrgByMdc(payGroupCnt,mdcCode,payGroupListDialog);
	        }
	    } );
	},param);
}

/**
 * 
 * @
 * @void
 * @ Discription: 添加付费病组
 * @paygroupAnalysis.js
 */
function addPayGroup() {
	var columns=[
	               	{"data": "ddesc","title":"DRG代码及描述","width":200,
	               		"render": function(obj, type, full) {
	               			return full.ccode +"-"+ full.ddesc ;
		             }
	           		},
	               	{"data": "InCaseCnt","title":"病例数" ,
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.InCaseCnt,0) ;
	           			}
	           		},
	               	{"data": "InCaseCntRank","title":"病例数排名"},
	               	{"data": "PayGroupOverFeeCnt","title":"费用超标病例数",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.PayGroupOverFeeCnt,2) ;
	           			}
	               	},
	               	{"data": "PayGroupOverFeeCntR","title":"超标病例占比(%)",
	               		"render": function(obj, type, full) {
	               			if(full.PayGroupOverFeeCnt&&full.InCaseCnt) {
	               				return formatNumPayGroup(full.PayGroupOverFeeCnt/full.InCaseCnt*100,2) ;
	               			} else {
	               				return formatNumPayGroup("0",2)  ;
	               			}
		                }
	           		},
	           		{"data": "AvgFee","title":"次均费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgFee,2) ;
	           			}
	           		},
	           		{"data": "AvgFeecc","title":"次均费用标杆",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgFeecc,2) ;
	           			}
	           		},
	           		{"data": "AvgDays","title":"平均住院日",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgDays,2) ;
	           			}
	           		},
	           		{"data": "AvgDayscc","title":"平均住院日标杆",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgDayscc,2) ;
	           			}
	           		},
	           		{"data": "operation","title":"操作",
	           			"render": function(obj, type, full) {
	           				return "<a action=\"1\" caseCnt=\""+full.InCaseCnt+"\" drgcode=\""+full.ccode+"\">添加</a>" ;
	           			}
	           		}
              ];
	$.post(contextPath + "/pages/common/top-dialog.jsp").done(function(data){
		var dialog  = $(data);
        dialog.find(".modal-body").css("min-height", "440px");
        dialog.find(".modal-body").css("width", "60%");
		dialog.find(".modal-title").html("付费病组添加");
		dialog.modal({
			keyboard: false,
			backdrop:"static"
		}).on({
			"hidden.bs.modal" : function(){
				$(this).remove();
				payGroupList();
			},
			"shown.bs.modal" : function(){
				dialog.find("#echartcq4").html("<table id=\"addPaygroupTable\" width='100%' class=\"table nowrap\"></table>");
				var addPaygroupTable = {"id":"addPaygroupTable","quotas":[
		       	                          {"code":"InCaseCnt","title":"入组病例数",
				       	   	           			"render": function(obj, type, full) {
				       		           				return formatNumPayGroup(full.InCaseCnt,0) ;
				       		           			}
		       	                          },
		       	                          {"code":"PayGroupOverFeeCnt","title":"超标病例数",
				       	   	           			"render": function(obj, type, full) {
				       		           				return formatNumPayGroup(full.PayGroupOverFeeCnt,0) ;
				       		           			}
		       	                          },
		       	                          {"code":"AvgFee","title":"次均费用",
				       	   	           			"render": function(obj, type, full) {
				       		           				return formatNumPayGroup(full.AvgFee,2) ;
				       		           			}
		       	                          },
		       	                          {"code":"AvgDays","title":"平均住院日",
				       	   	           			"render": function(obj, type, full) {
				       		           				return formatNumPayGroup(full.AvgDays,2) ;
				       		           			}
		       	                          }
		       	                        ],
          				       	                     "data":{} } ;
				var param = {"monitorType":"drgs","isGetCc":"1","compareType":"std"} ;
				// 付费病组维护，将非付费病组添加到付费病组
				param.msCode = "std_paygroup" ;
				param.isPayGroup = "0" ;
				// 查询所有病组
				$.when(loadDataPayGroup(addPaygroupTable,null,param),findAllDRGPayGroup()).done(function (data1,data2) {
					if(data2 && data2.data && addPaygroupTable.data.drgs) {
                        mergeList(data2.data, addPaygroupTable.data.drgs,"ccode") ;
                        for(var o in data2.data){
                        	if(data2.data[o].InCaseCnt === undefined) {
                                data2.data[o].InCaseCnt = 0 ;
							} else {
                                data2.data[o].InCaseCnt = Number(data2.data[o].InCaseCnt) ;
							}
						}
                        var paramsDataTables={lengthChange:false,ordering:false,stateSave:true,scrollX:true, scrollY:"300px" ,info:false,tableTitle:"付费病组维护",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
                        // 按照病例数进行排名
                        data2.data.sort(order("InCaseCnt",false));
                        for(var i = 0 ; i < data2.data.length ; i++ ) {
                            data2.data[i].InCaseCntRank = (i+1) ;
                        }
                        dialog.find("#echartcq4 #addPaygroupTable").dataTableBasic(columns,data2.data,paramsDataTables) ;
                        dialog.find("#echartcq4 #addPaygroupTable").on("click","a",function() {
                            // 执行添加操作
							if(Number($(this).attr("caseCnt"))>0){
                                updatePayGroup($(this).attr("drgCode"),$(this).attr("action"),$(this).parent().parent("tr"));
							} else {
								drgUI.alert("该病组没有病例数据,无法添加") ;
								return ;
							}
                        }) ;
					}
                })
			}
		});
 });
}

/**
 * @Description: 查询所有病组
 * @param  
 * @return  
 * @throws
 * @author chenhanlin
 * @date 2018/9/4 16:36
 */
function findAllDRGPayGroup(isPayGroup) {
	var dtd = $.Deferred();
	var param = drgUI.setAjaxData(tabId) ;
	param.isPayGroup = isPayGroup ;
    $.post(contextPath + "/payGroup/findAllDRG.dhc", param ).done(function(data) {
        dtd.resolve(data);
    })
    return dtd.promise();
}




/**
 * 
 * @@param drgCode
 * @@param action
 * @void
 * @ Discription: 更新付费病组
 * @paygroupAnalysis.js
 */
function updatePayGroup(drgCode,action,tr) {
	var param = drgUI.setAjaxData(tabId);
	param.action = action ;
	param.pardrgCode = drgCode;
	if(action==0)
	{//取消付费病组设定
		drgUI.confirm({
			content : '确认删除吗?',
			callSure : function() {
				$.post(contextPath + "/payGroup/updatePayFee.dhc", param ).done(function(data) {
					// 更新成功，删除该行
					if(data.data) {
						tr.remove() ;
						//清除全部缓存
						$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){});
					} else {
						console.log("error") ;
					}
				})
			}
		});
	} else {//新增付费病组
		$.post(contextPath + "/payGroup/updatePayFee.dhc",param).done(function(data) {
			// 更新成功，删除该行
			if(data.data) {
				tr.remove() ;
				//清除全部缓存
				$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){});
			} else {
				console.log("error") ;
			}
		})
	}
	
}

/**
 * 
 * @@param mdcCode
 * @void
 * @ Discription: 查询mdc下的付费病组
 * @paygroupAnalysis.js
 */
function findDrgByMdc(payGroupCnt,mdcCode,dialog) {
	var tid='id'+new Date().getTime();
	dialog.find("#" +mdcCode).html('<table id="'+tid+'" class="table"></table>') ;
	var columns=[
	               	{"data": "desc","title":"DRG代码及描述",
	               		"render": function(obj, type, full) {
	               			return  full.ccode +"-"+full.ddesc ;
		                     }
	           		},
	               	{"data": "PayGroupCnt","title":"病例数" ,
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.PayGroupCnt,0) ;
	           			}
	           		},
	               	{"data": "PayGroupCntRank","title":"病例数全院占比(%)",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.PayGroupCnt/payGroupCnt*100,2) ;
		                 }
	       			},
	               	{"data": "PayGroupOverFeeCnt","title":"费用超标病例数",
	               		"render": function(obj, type, full) {
	               			return formatNumPayGroup(full.PayGroupOverFeeCnt,2) ;
		                 }
	       			},
	               	{"data": "ExcessCnt_FR","title":"超标病例占比(%)",
	               		"render": function(obj, type, full) {
	               			if(full.PayGroupOverFeeCnt&&full.InCaseCnt) {
	               				return formatNumPayGroup(full.PayGroupOverFeeCnt/full.InCaseCnt*100,2) ;
	               			} else {
	               				return formatNumPayGroup("0",2)  ;
	               			}
		                }
	           		},
	           		{"data": "AvgFee","title":"次均费用",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgFee,2) ;
	           			}
	           		},
	           		{"data": "AvgFeecc","title":"次均费用标杆",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgFeecc,2) ;
	           			}
	           		},
	           		{"data": "AvgDays","title":"平均住院日",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgDays,2) ;
	           			}
	           		},
	           		{"data": "AvgDayscc","title":"平均住院日标杆",
	           			"render": function(obj, type, full) {
	           				return formatNumPayGroup(full.AvgDayscc,2) ;
	           			}
	           		},
	           		{"data": "operation","title":"操作",
	           			"render": function(obj, type, full) {
	           				return "<a action=\"0\" drgcode=\""+full.ccode+"\">删除</a>" ;
	           			}
	           		}
	              ];
	
	var paygroupManageDrgTable = {"id":tid,"quotas":[
				       	                          {"code":"PayGroupDrgCnt","title":"付费病组数"},
				       	                          {"code":"InCaseCnt","title":"入组病例数",
						       	   	           			"render": function(obj, type, full) {
						       		           				return formatNumPayGroup(full.InCaseCnt,0) ;
						       		           			}
				       	                          },
				       	                          {"code":"PayGroupCnt","title":"付费病组病例数",
						       	   	           			"render": function(obj, type, full) {
						       		           				return formatNumPayGroup(full.PayGroupCnt,0) ;
						       		           			}
				       	                          },
				       	                          {"code":"PayGroupOverFeeCnt","title":"费用超标病例数",
						       	   	           			"render": function(obj, type, full) {
						       		           				return formatNumPayGroup(full.PayGroupOverFeeCnt,0) ;
						       		           			}
				       	                          },
				       	                          {"code":"AvgFee","title":"次均费用",
						       	   	           			"render": function(obj, type, full) {
						       		           				return formatNumPayGroup(full.AvgFee,2) ;
						       		           			}
				       	                          },
				       	                          {"code":"AvgDays","title":"平均住院日",
						       	   	           			"render": function(obj, type, full) {
						       		           				return formatNumPayGroup(full.AvgDays,2) ;
						       		           			}
				       	                          },
				       	                          {"code":"PayGroupOverFeeDrgCnt","title":"付费超标病组组数"}
				       	                        ],
	              				       	                     "data":{} } ;
	var param = {"monitorType":"drgs","mdcCode":mdcCode,"isGetCc":"1","compareType":"std"} ;
	// 付费病组维护，将非付费病组添加到付费病组
	param.msCode = "std_paygroup" ;
	loadDataPayGroup(paygroupManageDrgTable,function(thisObj) {
		var paramsDataTables={searching:false,paging:true,lengthChange:false,ordering:false,stateSave:true,info:false,tableTitle:mdcCode+"下的付费病组",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		dialog.find("#"+tid).dataTableBasic(columns,thisObj.data.drgs,paramsDataTables);
	},param) ;
	dialog.find("#echartcq4 #"+tid+"").on("click","a",function() {
		// 执行删除操作
		updatePayGroup($(this).attr("drgCode"),$(this).attr("action"),$(this).parent().parent("tr"));
	}) ;
	
}

/**
 * 病组列表
 * @@param code 指标编码
 * @void
 * @ Discription:
 * @paygroupAnalysis.js
 */
function openDrgList(code) {
	var tabDesc = code=="PayGroupOverFeeDrgCnt"?"付费超标病组":"付费病组" ;
	var tabCode = "" ;
	var index = $("#"+tabId+ " #profitLossTab li.active").index();//当前被选中的顺序 0 病组 1科室
	var param = drgUI.setAjaxData(tabId) ;
	// 付费病组监测 全部病组
	if(code) {
		param.depCode = "" ;
		param.mdcCode = "" ;
		param.quotaCode = code ;
	} else if(index==0) { // 盈亏统计 MDC下病组
		param.mdcCode = $("#"+tabId+ " #selectedMdc").attr("code");
		tabCode = param.mdcCode ;
		tabDesc = $("#"+tabId+" #selectedMdc").text() ;
	} else { // 盈亏统计 科室下病组
		param.depCode = $("#"+tabId+ " #selectedDep").attr("code");
		tabCode = param.depCode ;
		tabDesc = $("#"+tabId+" #selectedDep").text() ;
	}
	param.pType = "1" ;
	openTab('/pages/paygroup/paygroup_drgslist.jsp',  tabDesc+"列表", "paygroup_drgslist"+tabCode+code , "paygroup_drgslist"+tabCode+code, param);
}